/**
 * 场馆页js
 * @author songchi@gz-zc.cn
 */
define(function(require, exports, module){
	
	var public = require('public');
	require('dialog');
	require('wdate');
	require('swiper');
	module.exports = {
			load:function(){
					public.load();
					$(".theme-list li:nth-child(3n)").css("margin-right", "0");
		            $(".out .num").css("right",($(".venue-banner").width()-1100)/2+50);
		            $(".banner-left").css("right",($(".venue-banner").width()-1100)/2+1100);
		            $(".banner-right").css("left",($(".venue-banner").width()-1100)/2+1100);
		            
		            $(".theme-list li img,.theme-list li p").click(function() {
				        $(".page-bg").addClass("act");
				        $(this).parent().children(".theme-img").addClass("act");
				    });

				    $(".theme-list .close").click(function() {
				        $(".page-bg").removeClass("act");
				        $(".theme-img").removeClass("act");
				    });
				    
				    
				    $(".theme-list li:nth-child(3n)").css("margin-right", "0");
		            $(".popup-bespeak li:nth-child(2n)").css("float", "right");

		            $(".bespeak").click(function() {
		                $(".page-bg").addClass("act");
		                $(".popup-bespeak").addClass("act");
		            });
		            $(".close").click(function() {
		                $(".page-bg").removeClass("act");
		                $(".popup-bespeak").removeClass("act");
		            });
				    

				    var mySwiper1 = new Swiper('.swiper-container1',{
				        pagination: '.pagination1',
				        loop:true,
				        grabCursor: true,
				        paginationClickable: true
				    })
				    $('.arrow-left1').on('click', function(e){
				        e.preventDefault()
				        mySwiper1.swipePrev()
				      })
				      $('.arrow-right1').on('click', function(e){
				        e.preventDefault()
				        mySwiper1.swipeNext()
				    })

				    var mySwiper2 = new Swiper('.swiper-container2',{
				        pagination: '.pagination2',
				        loop:true,
				        grabCursor: true,
				        paginationClickable: true
				    })
				    $('.arrow-left2').on('click', function(e){
				        e.preventDefault()
				        mySwiper2.swipePrev()
				      })
				      $('.arrow-right2').on('click', function(e){
				        e.preventDefault()
				        mySwiper2.swipeNext()
				    })

				    var mySwiper3 = new Swiper('.swiper-container3',{
				        pagination: '.pagination3',
				        loop:true,
				        grabCursor: true,
				        paginationClickable: true
				    })
				    $('.arrow-left3').on('click', function(e){
				        e.preventDefault()
				        mySwiper3.swipePrev()
				      })
				      $('.arrow-right3').on('click', function(e){
				        e.preventDefault()
				        mySwiper3.swipeNext()
				    })
		},
		
		show:function(){
			$(".bespeak").click(function() {
                $(".page-bg").addClass("act");
                $(".popup-bespeak").addClass("act");
                
                //判断是否登录
				$.get('/passport/is_login', function(data){
					if(data.status == 0){
						var realname = data.realname;
						var nickname = data.nickname;
						var mobile_phone = data.mobile_phone;
						var address = data.address;
						
						$('input[name="name"]').attr('value', realname);
						$('input[name="phone"]').attr('value', mobile_phone);;
						$('input[name="address"]').attr('value', address);;
					}
				})
                
                
                
            });
            $(".close").click(function() {
                $(".page-bg").removeClass("act");
                $(".popup-bespeak").removeClass("act");
            });
		},
		submit:function(){
			$('.submit').click(function(){
				var realname = $('input[name="name"]').val();
				var mobile_phone = $('input[name="phone"]').val();
				var address = $('input[name="address"]').val();
				var time = $('input[name="time"]').val();
				var dinner_type = $("#venue").val();
				
				if(!realname){
					$(".message").html("用户名不能为空");
					$('input[name="name"]').focus();
					return false;
				}
				
				if(!mobile_phone){
					$(".message").html("电话不能为空");
					$('input[name="phone"]').focus();
					return false;
				}

				
				if(!time){
					$(".message").html("选择预约时间");
					$('input[name="time"]').focus();
					return false;
				}
				
				$.post('/venue/appoint', {realname:realname, mobile_phone:mobile_phone, address:address, dinner_type:dinner_type, time:time, id:id}, function(data){
					if(data.status == 0){
						ajaxDialog(data.msg, '', '/venue/email?mobile_phone='+data.data.mobile_phone+"&realname="+data.data.realname+"&address="+data.data.address+"&customer_id="+data.data.customer_id, '/venue/detail?id='+id);
					}else{
						showDialog(data.msg)
					}
				})
				
			})
		},
		
		datepick:function(){
			$(".Wdate").focus(function(){
	            WdatePicker({dateFmt:'yyyy-MM-dd'})
	        });
			$(".tdate").focus(function(){
				WdatePicker({dateFmt:'HH:mm'})
			});
		},
	
	}
	
	function showDialog(msg, title, url){

    	var title = arguments[1] ? arguments[1] : '提示信息';
    	var url = arguments[2] ? arguments[2] : '';
        var d = dialog({
        	id:'FVASDF',
            title: title,
            content: msg,
            width: 300,
            okValue: '确定',
            ok: function () {
            	if(url != '')
            	{
            		window.location.href=url;
            	}
                return true;
            }
        });
        d.showModal();
    }
	
	//url ajax请求地址   url1跳转地址
	function ajaxDialog(msg, title, url, url1){

    	var title = arguments[1] ? arguments[1] : '提示信息';
    	var url = arguments[2] ? arguments[2] : '';
    	var url1 = arguments[3] ? arguments[3] : '';
        var d = dialog({
        	id:'FVASDF',
            title: title,
            content: msg,
            width: 300,
            okValue: '确定',
            ok: function () {
            	
            	if(url1 != '')
            	{
            		window.location.href=url1;
            	}
            }
        });
        d.showModal();
        if(url != '')
    	{
    		$.get(url, function(data){
			})
    	}
    }
	
})